//
//  ComNoteListTableview.m
//  DogeLegs
//
//  Created by 宋华 on 2017/8/20.
//  Copyright © 2017年 宋华. All rights reserved.
//

#import "ComNoteListTableview.h"
#import "ComNoteLIstCell.h"
#import "NoteMode.h"

static NSString *ComNoteLIstIdentifier = @"ComNoteLIstCell";


@implementation ComNoteListTableview


- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        [self defaultConfiguration];
    }
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    [self defaultConfiguration];
}

- (void)defaultConfiguration {
    self.hOrF = HaveHeadOrFooter_all;
    self.dataSource = self;
    self.delegate = self;
    [self registerNib:[UINib nibWithNibName:ComNoteLIstIdentifier bundle:nil] forCellReuseIdentifier:ComNoteLIstIdentifier];
    self.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - UITableView Delegate & Datasource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 
    return self.notelists.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WeakSelf(ws);
    NSInteger rowIndex = indexPath.row;
    NSInteger sectionIndex = indexPath.section;
    NoteMode  *mode = [self.notelists objectAtIndex:rowIndex];
    ComNoteLIstCell  *cell = [tableView dequeueReusableCellWithIdentifier:ComNoteLIstIdentifier forIndexPath:indexPath];
    [cell cellWillDisplay:mode];
    cell.revLikeBlock = ^{
        if (ws.revLikeBlock) {
            ws.revLikeBlock(rowIndex);
        }
    };
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    if (rowIndex % 2 == 0) {
//        cell.backgroundColor = [UIColor redColor];
//    } else {
//        cell.backgroundColor = [UIColor orangeColor];
//
//    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger sectionIndex = indexPath.section;
    NSInteger rowIndex = indexPath.row;
    NoteMode  *mode = [self.notelists objectAtIndex:rowIndex];

    return mode.noteCellHeight;
}


@end
